package com.design.patterns.list.iterator.concreteiterator;

import com.design.patterns.list.iterator.aggregate.Department;

import java.util.Iterator;
import java.util.List;

/**
 * @author Wangzhiwen
 */
public class ArtCollegeIterator implements Iterator<Department> {

    private List<Department> departments;
    private int index;

    public ArtCollegeIterator(List<Department> departments) {
        this.departments = departments;
    }

    @Override
    public boolean hasNext() {
        if (index < departments.size()){
            index++;
            return true;
        }else {
            return false;
        }
    }

    @Override
    public Department next() {
        return departments.get(index);
    }

    @Override
    public void remove() {
        departments.remove(index);
    }

    // 实际还需要判断索引是否越界的问题
}
